// 服务管理

import { alovaInstance as alova } from './alova'
import type { AddService, AddServicePackage, AddServicePackageBase, ApiCommonResponse, MutipleType } from '@/types'

// 服务方式列表
export function queryWayList() {
  return alova.Get<ApiCommonResponse>('/way/list', {
    localCache: void 0,
  })
}

// 等级列表
export function queryLevelList() {
  return alova.Get<ApiCommonResponse>('/level/list', {
    localCache: void 0,
  })
}

// 标签列表
export function queryTagList() {
  return alova.Get<ApiCommonResponse>('/tag/list', {
    localCache: void 0,
  })
}

// 新增等级
export const addCareLevel = (name: string) => alova.Post<ApiCommonResponse>('/level/add', { name })

// 删除等级
export const deleteCareLevel = (id: number) => alova.Delete<ApiCommonResponse>(`/level/${id}`)

/**
 * @description: 增加服务配置
 * @return {*}
 */
export const addServerConfig = (data: any) => alova.Post<ApiCommonResponse>('/setting/add', data)

/**
 * @description: 保存服务配置
 * @return {*}
 */
export const saveServerConfig = (data: any, id: number) => alova.Put<ApiCommonResponse>('/setting/save', { ...data, id })

/**
 * @description: 查询所有服务配置
 * @return {*}
 */
export function queryServerConfig() {
  return alova.Get<ApiCommonResponse>('/setting/list', {
    localCache: void 0,
  })
}

/**
 * @description: 根据等级查询服务配置详情
 * @return {*}
 */

export function queryServerConfigByLevel(id: number, packageID?: MutipleType) {
  const params: any = {
    levelID: id,
  }
  if (packageID)
    params.packageID = packageID

  return alova.Post<ApiCommonResponse>(`/setting/tag/level`, { ...params })
}

/**
 * @description: 服务包详情
 * @return {*}
 */
export function queryServerPackageConfig(id: MutipleType) {
  return alova.Get<ApiCommonResponse>(`/package/${id}/detail`, {
    localCache: void 0,
  })
}

/**
 * @description: 增加服务包
 * @return {*}
 */
export const addServicePackage = (data: AddService) => alova.Post<ApiCommonResponse>('/package/add', { ...data })

/**
 * @description: 保存服务包基础信息
 * @return {*}
 */
export const saveServicePackageBase = (id: string | number, data: AddServicePackageBase) => alova.Put<ApiCommonResponse>(`/package/${id}/save`, { ...data })

/**
 * @description: 保存服务包配置
 * @return {*}
 */
export const saveServicePackageConfig = (id: string | number, data: AddServicePackage) => alova.Put<ApiCommonResponse>(`/package/${id}/setting/save`, { ...data })

/**
 * @description: 查询所有服务包
 * @return {*}
 */
export function queryServicePackage() {
  return alova.Get<ApiCommonResponse>(`/package/list`, {
    localCache: void 0,
  })
}
